#ifndef A8_ATOMIC_H
#define A8_ATOMIC_H

#ifndef WIN32
namespace a8
{
    static inline unsigned long AtomicAddLong(volatile unsigned long  *p, unsigned long v)
    {
        return __sync_fetch_and_add(p, v);
    }

    static inline unsigned long  AtomicSubLong(volatile unsigned long *p, unsigned long v)
    {
      return __sync_fetch_and_sub(p, v);
    }
}

#define InterlockedIncrement(inc) a8::AtomicAddLong(inc, (unsigned long)1)
#define InterlockedDecrement(dec) a8::AtomicDecLong(dec, (unsigned long)1)
#endif

#endif
